Skip to content

Refactor git to use runtime node:zlib - #32

Merged
aron-cf merged 1 commit into
mainfrom
zlib
Jul 31, 2026
Merged

Refactor git to use runtime node:zlib#32
aron-cf merged 1 commit into
mainfrom
zlib

Conversation

@aron-cf

@aron-cf aron-cf commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

This change keeps git out of the default @cloudflare/computer bundle while preserving first-class git support for callers that opt in. Previously, the main Workspace graph made isomorphic-git reachable because workspace.git was wired by default. That meant non-git Workers could still carry a lazy git chunk in their build. At the same time, git users paid for isomorphic-git's bundled JavaScript pako compression implementation even though Workers provide node:zlib.

The new shape makes git an explicit Workspace capability. The default package graph no longer imports the git implementation. Callers that need git import createGitClient from @cloudflare/computer/git and pass the returned factory into WorkspaceOptions.git. That git subpath bundles isomorphic-git lazily and aliases pako to a small node:zlib compatibility layer, so git users still get the smaller compression payload while non-git users pay no git cost.

Default filesystem and shell usage does not configure git:

import { Workspace } from "@cloudflare/computer";

const workspace = new Workspace({
  storage: ctx.storage,
});

await workspace.fs.writeFile("/notes.md", "hello\n");

Git usage opts in through the git subpath:

import { Workspace } from "@cloudflare/computer";
import { createGitClient } from "@cloudflare/computer/git";

const workspace = new Workspace({
  storage: ctx.storage,
  git: createGitClient(),
  defaultGitIdentity: {
    name: "Agent",
    email: "agent@example.test",
  },
});

await workspace.git.init();
await workspace.fs.writeFile("/notes.md", "hello\n");
await workspace.git.add({ paths: ["notes.md"] });
await workspace.git.commit({ message: "add notes" });

Advanced tests and custom adapters can configure the factory before binding it to a workspace:

import { createGitClient } from "@cloudflare/computer/git";

const gitFactory = createGitClient({ adapter });
const git = gitFactory({ ws: workspace });

If workspace.git is accessed without WorkspaceOptions.git, it now throws a clear configuration error. The worker backend's built-in git command follows the same rule because it forwards to the host workspace's git client.

The bundle outcome is now split by use case. A default @cloudflare/computer import does not reference the git chunk, isomorphic-git, pako, or node:zlib. Git users opt into the git entrypoint and get the Worker-optimized lazy git chunk. In the current build, dist/index.js is about 165 KB raw and 36 KB gzip, the git wrapper is about 102 KB raw and 21 KB gzip, and the lazy isomorphic-git chunk is about 574 KB raw and 127 KB gzip.

Verification run locally:

npm run build --workspace @cloudflare/computer
npm run typecheck --workspace @cloudflare/computer
npm test --workspace @cloudflare/computer
npm run check

The package README and git interface documentation were updated to show the opt-in API and explain that the default package graph stays free of git.

@pkg-pr-new

pkg-pr-new Bot commented Jul 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/computer/@cloudflare/computer@32

commit: 70933c3

Move the git client behind an explicit Workspace option so the default package graph no longer pulls in isomorphic-git. The git subpath now exposes createGitClient() as a factory provider and keeps the pako replacement local to the bundled git entrypoint.

Add a node:zlib-backed pako shim for the isomorphic-git paths used by the workspace git client. This preserves automatic git support for callers that opt in while avoiding pako for Worker builds that only use the core workspace.
@aron-cf
aron-cf merged commit e02e93c into main Jul 31, 2026
11 checks passed
@aron-cf
aron-cf deleted the zlib branch July 31, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant